Page({
  data: {
    classId: 0,
    className: '',
    week: 1,
    semester: 1, // 添加学期字段
    semesterList: [{ id: 1, name: '第一学期' }, { id: 2, name: '第二学期' }], // 添加学期列表
    semesterIndex: 0, // 添加学期索引
    courseList: [{ id: 0, name: '请选择课程' }],
    courseIndex: 0,
    teacherList: [{ id: 0, name: '请选择教师' }],
    teacherIndex: 0,
    roomList: [{ id: 0, name: '请选择教室' }],
    roomIndex: 0,
    weekdays: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    dayIndex: 0,
    periods: [
      { id: 0, name: '第1节', time: '08:00-08:45' },
      { id: 1, name: '第2节', time: '08:55-09:40' },
      { id: 2, name: '第3节', time: '10:00-10:45' },
      { id: 3, name: '第4节', time: '10:55-11:40' },
      { id: 4, name: '第5节', time: '14:00-14:45' },
      { id: 5, name: '第6节', time: '14:55-15:40' },
      { id: 6, name: '第7节', time: '16:00-16:45' },
      { id: 7, name: '第8节', time: '16:55-17:40' },
      { id: 8, name: '第9节', time: '19:00-19:45' },
      { id: 9, name: '第10节', time: '19:55-20:40' }
    ],
    periodIndex: 0,
    startWeek: '',
    endWeek: '',
    tempCourse: null,
    isLoading: false,
    showAddCourseModal: false,
    newCourseName: '',
    newCourseCredits: '',
    newCourseTeacherIndex: 0,
    isNewCourse: false
  },

  onLoad: function(options) {
    const { classId, week, day, period, courseId, timetableId, isAdd } = options;
    
    console.log('编辑页面参数:', options);
    
    this.setData({
      classId: classId,
      week: week || 1,
      dayIndex: day ? Number(day) - 1 : 0,
      periodIndex: period || 0,
      courseId: courseId,
      timetableId: timetableId,
      isAdd: isAdd === 'true'
    });
    
    // 初始化数据
    this.initData();
    
    // 如果是编辑模式，获取课程详情
    if (timetableId && !isAdd) {
      this.fetchCourseDetail(timetableId);
    }
  },

  // 初始化所有数据
  // 在initData函数中添加学期格式检查
  initData: function() {
    this.fetchClassName();
    this.fetchCourseList();
    this.fetchTeacherList();
     this.fetchRoomList();
    // 尝试从后端获取学期列表
    this.fetchSemesters();
  },
  
  // 获取学期列表
  fetchSemesters: function() {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    console.log('开始请求学期列表');
    
    wx.request({
      // 修改为与主页面相同的API路径
      url: `${serverUrl}/api/courses/semesters`,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        console.log('学期列表响应:', res);
        if (res.statusCode === 200) {
          const semesters = res.data || [];
          
          if (semesters.length > 0) {
            // 转换为前端需要的格式，与主页面保持一致
            const semesterList = semesters.map(item => {
              const parts = item.id.split('-');
              let displayName = item.name || item.id;
              
              if (parts.length === 3) {
                const startYear = parts[0];
                const endYear = parts[1];
                const term = parts[2] === '1' ? '第一学期' : '第二学期';
                displayName = `${startYear}-${endYear}学年${term}`;
              }
              
              return {
                id: item.id,
                name: displayName
              };
            });
            
            this.setData({
              semesterList: semesterList,
              semesterIndex: 0,
              semester: semesterList[0].id
            });
          } else {
            console.error('获取学期列表成功但数据为空');
            this.setDefaultSemesters();
          }
        } else {
          console.error('获取学期列表失败:', res);
          this.setDefaultSemesters();
        }
      },
      fail: (err) => {
        console.error('获取学期列表请求失败:', err);
        this.setDefaultSemesters();
      }
    });
  },
  
  // 设置默认学期数据
  setDefaultSemesters: function() {
    // 获取当前年份
    const currentYear = new Date().getFullYear();
    
    // 使用与主页面一致的学期格式
    this.setData({
      semesterList: [
        { id: `${currentYear}-${currentYear+1}-1`, name: `${currentYear}-${currentYear+1}学年第一学期` },
        { id: `${currentYear-1}-${currentYear}-2`, name: `${currentYear-1}-${currentYear}学年第二学期` }
      ],
      semesterIndex: 0,
      semester: `${currentYear}-${currentYear+1}-1`
    });
  },
  
  // 不再需要这个方法，可以删除或保留注释掉
  // fetchSemesters: function() {
  //   // ...
  // },
  
  // 学期选择变化
  semesterChange: function(e) {
    const index = e.detail.value;
    this.setData({
      semesterIndex: index,
      semester: this.data.semesterList[index].id
    });
  },
  // 获取班级名称
  fetchClassName: function() {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    wx.request({
      url: `${serverUrl}/api/admin/timetable/classes/${this.data.classId}`,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        if (res.statusCode === 200) {
          this.setData({
            className: res.data.name
          });
        } else {
          console.error('获取班级名称失败:', res);
          this.setData({
            className: '未知班级'
          });
        }
      },
      fail: (err) => {
        console.error('获取班级名称请求失败:', err);
        this.setData({
          className: '未知班级'
        });
      }
    });
  },

  // 获取教室列表
  fetchRoomList: function() {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    console.log('开始请求教室列表:', `${serverUrl}/api/admin/timetable/rooms`);
    
    wx.request({
      url: `${serverUrl}/api/admin/timetable/rooms`,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        console.log('教室列表响应:', res);
        if (res.statusCode === 200) {
          const rooms = [{ id: 0, name: '请选择教室' }, ...res.data];
          this.setData({
            roomList: rooms
          });
        } else {
          console.error('获取教室列表失败:', res);
          // 使用模拟数据确保界面可用
          this.setData({
            roomList: [
              { id: 0, name: '请选择教室' },
              { id: 1, name: '教学楼A-101' },
              { id: 2, name: '教学楼A-102' },
              { id: 3, name: '教学楼B-201' },
              { id: 4, name: '教学楼B-202' }
            ]
          });
        }
      },
      fail: (err) => {
        console.error('获取教室列表请求失败:', err);
        // 使用模拟数据确保界面可用
        this.setData({
          roomList: [
            { id: 0, name: '请选择教室' },
            { id: 1, name: '教学楼A-101' },
            { id: 2, name: '教学楼A-102' },
            { id: 3, name: '教学楼B-201' },
            { id: 4, name: '教学楼B-202' }
          ]
        });
      }
    });
  },

  // 获取教师列表
  fetchTeacherList: function() {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    console.log('开始请求教师列表:', `${serverUrl}/api/admin/timetable/teachers`);
    
    wx.request({
      url: `${serverUrl}/api/admin/timetable/teachers`,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        console.log('教师列表响应:', res);
        if (res.statusCode === 200) {
          const teachers = [{ id: 0, name: '请选择教师' }, ...res.data];
          this.setData({
            teacherList: teachers
          });
        } else {
          console.error('获取教师列表失败:', res);
          // 使用模拟数据确保界面可用
          this.setData({
            teacherList: [
              { id: 0, name: '请选择教师' },
              { id: 1, name: '张老师' },
              { id: 2, name: '李老师' },
              { id: 3, name: '王老师' }
            ]
          });
        }
      },
      fail: (err) => {
        console.error('获取教师列表请求失败:', err);
        // 使用模拟数据确保界面可用
        this.setData({
          teacherList: [
            { id: 0, name: '请选择教师' },
            { id: 1, name: '张老师' },
            { id: 2, name: '李老师' },
            { id: 3, name: '王老师' }
          ]
        });
      }
    });
  },

  // 获取课程列表
  fetchCourseList: function() {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    console.log('开始请求课程列表:', `${serverUrl}/api/admin/timetable/courses`);
    
    wx.request({
      url: `${serverUrl}/api/admin/timetable/courses`,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        console.log('课程列表响应:', res);
        if (res.statusCode === 200) {
          const courses = [{ id: 0, name: '请选择课程' }, ...res.data];
          this.setData({
            courseList: courses
          });
        } else {
          console.error('获取课程列表失败:', res);
          // 使用模拟数据确保界面可用
          this.setData({
            courseList: [
              { id: 0, name: '请选择课程' },
              { id: 1, name: '高等数学' },
              { id: 2, name: '大学英语' },
              { id: 3, name: '数据结构' },
              { id: 4, name: '计算机网络' }
            ]
          });
        }
      },
      fail: (err) => {
        console.error('获取课程列表请求失败:', err);
        // 使用模拟数据确保界面可用
        this.setData({
          courseList: [
            { id: 0, name: '请选择课程' },
            { id: 1, name: '高等数学' },
            { id: 2, name: '大学英语' },
            { id: 3, name: '数据结构' },
            { id: 4, name: '计算机网络' }
          ]
        });
      }
    });
  },

  // 获取课程详情（编辑模式）
  fetchCourseDetail: function(timetableId) {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    wx.showLoading({
      title: '加载课程信息...',
    });
    
    wx.request({
      // 修改为正确的API路径，与课程详情页保持一致
      url: `${serverUrl}/api/admin/timetable/detail/${timetableId}`,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        wx.hideLoading();
        
        if (res.statusCode === 200) {
          const courseData = res.data;
          console.log('获取到的课程详情:', courseData);
          
          // 查找课程、教师和教室的索引
          const courseIndex = this.data.courseList.findIndex(item => item.id === courseData.courseId);
          const teacherIndex = this.data.teacherList.findIndex(item => item.id === courseData.teacherId);
          const roomIndex = this.data.roomList.findIndex(item => item.id === courseData.roomId);
          
          this.setData({
            courseIndex: courseIndex > 0 ? courseIndex : 0,
            teacherIndex: teacherIndex > 0 ? teacherIndex : 0,
            roomIndex: roomIndex > 0 ? roomIndex : 0,
            dayIndex: courseData.day - 1,
            periodIndex: courseData.period,
            startWeek: courseData.startWeek || 1,
            endWeek: courseData.endWeek || 20
          });
        } else {
          wx.showToast({
            title: '获取课程信息失败',
            icon: 'none'
          });
        }
      },
      fail: (err) => {
        wx.hideLoading();
        console.error('获取课程详情请求失败:', err);
        wx.showToast({
          title: '网络错误，请重试',
          icon: 'none'
        });
      }
    });
  },

  // 显示添加课程对话框
  showAddCourseDialog: function() {
    this.setData({
      showAddCourseModal: true,
      newCourseName: '',
      newCourseCredits: '',
      newCourseTeacherIndex: 0
    });
  },

  // 隐藏添加课程对话框
  hideAddCourseDialog: function() {
    this.setData({
      showAddCourseModal: false
    });
  },

  // 输入新课程名称
  inputNewCourseName: function(e) {
    this.setData({
      newCourseName: e.detail.value
    });
  },

  // 输入新课程学分
  inputNewCourseCredits: function(e) {
    this.setData({
      newCourseCredits: e.detail.value
    });
  },

  // 新课程教师选择变化
  newCourseTeacherChange: function(e) {
    this.setData({
      newCourseTeacherIndex: e.detail.value
    });
  },

  // 保存新课程
  saveNewCourse: function() {
    // 验证输入
    if (!this.data.newCourseName.trim()) {
      wx.showToast({
        title: '请输入课程名称',
        icon: 'none'
      });
      return;
    }
    
    if (!this.data.newCourseCredits) {
      wx.showToast({
        title: '请输入学分',
        icon: 'none'
      });
      return;
    }
    
    if (this.data.newCourseTeacherIndex === 0) {
      wx.showToast({
        title: '请选择教师',
        icon: 'none'
      });
      return;
    }

    // 生成课程代码
    const courseCode = 'C' + new Date().getTime().toString().slice(-6);
    
    // 创建临时课程对象
    const tempCourse = {
      name: this.data.newCourseName.trim(),
      credits: parseInt(this.data.newCourseCredits),
      courseCode: courseCode,
      teacherId: this.data.teacherList[this.data.newCourseTeacherIndex].id,
      teacherName: this.data.teacherList[this.data.newCourseTeacherIndex].name
    };

    // 保存临时课程数据
    this.setData({
      tempCourse: tempCourse,
      isNewCourse: true,
      showAddCourseModal: false,
      courseList: [...this.data.courseList, {
        id: 'temp_' + courseCode,
        name: tempCourse.name
      }],
      courseIndex: this.data.courseList.length // 自动选中新添加的课程
    });

    wx.showToast({
      title: '请继续设置课程时间等信息',
      icon: 'none',
      duration: 2000
    });
  },

  // 验证表单
  // 修改validateForm函数
  validateForm: function() {
    if (this.data.courseIndex === 0) {
      wx.showToast({
        title: '请选择课程',
        icon: 'none'
      });
      return false;
    }
    
    if (this.data.teacherIndex === 0) {
      wx.showToast({
        title: '请选择教师',
        icon: 'none'
      });
      return false;
    }
    
    if (this.data.roomIndex === 0) {
      wx.showToast({
        title: '请选择教室',
        icon: 'none'
      });
      return false;
    }
    
    if (!this.data.startWeek || !this.data.endWeek) {
      wx.showToast({
        title: '请输入周次范围',
        icon: 'none'
      });
      return false;
    }
    
    const startWeek = parseInt(this.data.startWeek);
    const endWeek = parseInt(this.data.endWeek);
    
    if (startWeek > endWeek) {
      wx.showToast({
        title: '起始周不能大于结束周',
        icon: 'none'
      });
      return false;
    }
    
    if (endWeek > this.data.maxWeeks) {
      wx.showToast({
        title: `结束周不能超过${this.data.maxWeeks}周`,
        icon: 'none'
      });
      return false;
    }
    
    return true;
  },

  // 保存课程 - 主要的添加/编辑课程功能
  // 保存课程信息
  saveCourse: function() {
    // 表单验证
    if (!this.validateForm()) {
      return;
    }
    
    // 提交数据
    wx.showLoading({
      title: '保存中...',
    });
    
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    // 如果是新建的临时课程，先创建课程
    if (this.data.isNewCourse && this.data.tempCourse) {
      this.createNewCourse();
    } else {
      // 如果是选择现有课程，直接创建课程表记录
      const courseId = this.data.courseList[this.data.courseIndex].id;
      
      // 检查课程ID是否有效
      if (!courseId || isNaN(parseInt(courseId))) {
        wx.hideLoading();
        wx.showToast({
          title: '课程ID无效，请重新选择课程',
          icon: 'none'
        });
        return;
      }
      
      this.createTimetableEntry(courseId);
    }
  },

  // 创建新课程
  createNewCourse: function() {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';
    
    // 生成时间
    const now = new Date();
    const startTime = now.toISOString().slice(0, 19).replace('T', ' ');
    const endTime = new Date(now.getTime() + 4 * 30 * 24 * 60 * 60 * 1000)
      .toISOString().slice(0, 19).replace('T', ' ');
  
    // 格式化学期 - 添加这段代码
    let formattedSemester = this.data.semester;
    if (formattedSemester && (formattedSemester === '1' || formattedSemester === '2' || formattedSemester === 1 || formattedSemester === 2)) {
      // 如果学期只是简单的1或2，则格式化为正确的格式
      const currentYear = new Date().getFullYear();
      if (formattedSemester == '1' || formattedSemester == 1) {
        formattedSemester = `${currentYear}-${currentYear+1}-1`;
      } else {
        formattedSemester = `${currentYear-1}-${currentYear}-2`;
      }
      console.log('格式化学期:', formattedSemester);
    }
  
    // 准备课程数据 - 使用格式化后的学期
    const courseData = {
      name: this.data.tempCourse.name,
      credits: parseInt(this.data.tempCourse.credits),
      courseCode: this.data.tempCourse.courseCode,
      teacherId: parseInt(this.data.tempCourse.teacherId),
      startTime: startTime,
      endTime: endTime,
      weekday: parseInt(this.data.dayIndex) + 1,
      weeks: `${parseInt(this.data.startWeek)}-${parseInt(this.data.endWeek)}`,
      semester: formattedSemester  // 使用格式化后的学期
    };
    
    console.log('创建课程数据:', courseData);
    console.log('学期值类型和值:', typeof formattedSemester, formattedSemester);
  
    // 先创建课程
    wx.request({
      url: `${serverUrl}/api/admin/courses`,
      method: 'POST',
      header: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      data: courseData,
      success: (res) => {
        if (res.statusCode === 201) {
          // 创建课程成功后，继续创建课程表记录
          const courseId = res.data.id;
          this.createTimetableEntry(courseId);
        } else {
          wx.hideLoading();
          console.error('创建课程失败:', res);
          wx.showToast({
            title: res.data.message || '创建课程失败',
            icon: 'none'
          });
        }
      },
      fail: (err) => {
        wx.hideLoading();
        console.error('创建课程失败:', err);
        wx.showToast({
          title: '网络错误，请重试',
          icon: 'none'
        });
      }
    });
  },

  // 创建课程表记录
  createTimetableEntry: function(courseId) {
    const app = getApp();
    const serverUrl = app.globalData.serverUrl || 'http://localhost:3000';

    // 检查课程ID是否有效
    if (!courseId || isNaN(parseInt(courseId))) {
      wx.hideLoading();
      wx.showToast({
        title: '课程ID无效，请重新选择课程',
        icon: 'none'
      });
      return;
    }

    // 检查课程列表是否已设置学期格式
    let formattedSemester = this.data.semester;
    if (formattedSemester && (formattedSemester === '1' || formattedSemester === '2' || formattedSemester === 1 || formattedSemester === 2)) {
      // 如果学期只是简单的1或2，则格式化为正确的格式
      const currentYear = new Date().getFullYear();
      if (formattedSemester == '1' || formattedSemester == 1) {
        formattedSemester = `${currentYear}-${currentYear+1}-1`;
      } else {
        formattedSemester = `${currentYear-1}-${currentYear}-2`;
      }
      console.log('格式化学期:', formattedSemester);
    }

    // 确保所有必要的参数都是有效的数字
    const timetableData = {
      classId: parseInt(this.data.classId) || 0,
      courseId: parseInt(courseId) || 0,
      teacherId: this.data.isNewCourse ? 
        parseInt(this.data.tempCourse.teacherId) || 0 : 
        parseInt(this.data.teacherList[this.data.teacherIndex].id) || 0,
      roomId: parseInt(this.data.roomList[this.data.roomIndex].id) || 0,
      day: parseInt(this.data.dayIndex) + 1,
      period: parseInt(this.data.periodIndex),
      startWeek: parseInt(this.data.startWeek) || 1,
      endWeek: parseInt(this.data.endWeek) || 20,
      week: parseInt(this.data.week) || 1,
      semester: formattedSemester  // 使用格式化后的学期
    };

    // 添加详细的调试日志
    console.log('========== 课程表创建调试信息 ==========');
    console.log('1. 原始数据:', {
      classId: this.data.classId,
      courseId: courseId,
      teacherId: this.data.isNewCourse ? this.data.tempCourse.teacherId : this.data.teacherList[this.data.teacherIndex].id,
      roomId: this.data.roomList[this.data.roomIndex].id,
      dayIndex: this.data.dayIndex,
      periodIndex: this.data.periodIndex,
      startWeek: this.data.startWeek,
      endWeek: this.data.endWeek,
      week: this.data.week,
      semester: this.data.semester
    });
    
    console.log('2. 处理后数据:', timetableData);
    
    console.log('3. 数据类型检查:', {
      classId: typeof timetableData.classId + ' => ' + timetableData.classId,
      courseId: typeof timetableData.courseId + ' => ' + timetableData.courseId,
      teacherId: typeof timetableData.teacherId + ' => ' + timetableData.teacherId,
      roomId: typeof timetableData.roomId + ' => ' + timetableData.roomId,
      day: typeof timetableData.day + ' => ' + timetableData.day,
      period: typeof timetableData.period + ' => ' + timetableData.period,
      startWeek: typeof timetableData.startWeek + ' => ' + timetableData.startWeek,
      endWeek: typeof timetableData.endWeek + ' => ' + timetableData.endWeek,
      week: typeof timetableData.week + ' => ' + timetableData.week,
      semester: typeof timetableData.semester + ' => ' + timetableData.semester
    });
    
    console.log('4. 验证结果:', {
      hasClassId: !!timetableData.classId,
      hasCourseId: !!timetableData.courseId,
      hasTeacherId: !!timetableData.teacherId,
      hasRoomId: !!timetableData.roomId,
      hasDay: !!timetableData.day,
      hasPeriod: timetableData.period !== undefined,
      hasStartWeek: !!timetableData.startWeek,
      hasEndWeek: !!timetableData.endWeek,
      hasWeek: !!timetableData.week,
      hasSemester: !!timetableData.semester
    });
    
    console.log('5. 请求URL:', `${serverUrl}/api/admin/timetable`);
    console.log('6. 请求方法: POST');
    console.log('====================================');

    // 验证所有必要参数
    if (!timetableData.classId || !timetableData.courseId || 
        !timetableData.teacherId || !timetableData.roomId || 
        !timetableData.day || timetableData.period === undefined || 
        !timetableData.startWeek || !timetableData.endWeek || 
        !timetableData.week || !timetableData.semester) {
      wx.hideLoading();
      wx.showToast({
        title: '请填写所有必要信息',
        icon: 'none'
      });
      return;
    }

    // 确定请求方法和URL
    let method = 'POST';
    let url = `${serverUrl}/api/admin/timetable`;
    
    // 如果是编辑模式，使用PUT方法
    if (this.data.timetableId && !this.data.isAdd) {
      method = 'PUT';
      url = `${serverUrl}/api/admin/timetable/${this.data.timetableId}`;
    }

    // 在请求前再次确认学期字段已包含
    console.log('发送到服务器的数据:', timetableData);
    console.log('学期值:', timetableData.semester);

    wx.request({
      url: url,
      method: method,
      data: timetableData,
      header: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        console.log('8. 服务器响应:', res);
        wx.hideLoading();
        if (res.statusCode === 201 || res.statusCode === 200) {
          wx.showToast({
            title: '保存成功',
            icon: 'success'
          });
          
          setTimeout(() => {
            wx.navigateBack({
              delta: 1,
              success: () => {
                // 通知上一页刷新数据
                const pages = getCurrentPages();
                if (pages.length >= 2) {
                  const prevPage = pages[pages.length - 2];
                  if (prevPage && prevPage.fetchTimetableData) {
                    prevPage.fetchTimetableData();
                  }
                }
              }
            });
          }, 1500);
        } else {
          console.error('9. 保存失败详情:', {
            状态码: res.statusCode,
            响应数据: res.data,
            错误信息: res.data.message
          });
          wx.showToast({
            title: res.data.message || '保存失败',
            icon: 'none'
          });
        }
      },
      fail: (err) => {
        console.error('10. 请求失败详情:', err);
        wx.hideLoading();
        wx.showToast({
          title: '网络错误，请重试',
          icon: 'none'
        });
      }
    });
  },

  // 提交表单 - 简化为调用saveCourse
  submitForm: function() {
    this.saveCourse();
  },

  // 返回上一页
  goBack: function() {
    wx.navigateBack();
  },

  // 课程选择变化
  courseChange: function(e) {
    this.setData({
      courseIndex: e.detail.value
    });
  },

  // 教师选择变化
  teacherChange: function(e) {
    this.setData({
      teacherIndex: e.detail.value
    });
  },

  // 教室选择变化
  roomChange: function(e) {
    this.setData({
      roomIndex: e.detail.value
    });
  },

  // 星期选择变化
  dayChange: function(e) {
    this.setData({
      dayIndex: e.detail.value
    });
  },

  // 节次选择变化
  periodChange: function(e) {
    this.setData({
      periodIndex: e.detail.value
    });
  },

  // 输入起始周
  startWeekInput: function(e) {
    this.setData({
      startWeek: e.detail.value
    });
  },
  
  // 输入结束周
  endWeekInput: function(e) {
    this.setData({
      endWeek: e.detail.value
    });
  }
});